<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var name = 'Tom';
        (function () {
            if (typeof name == 'undefined') {
                name = 'Jack';
                console.log('Goodbye ' + name);
            } else {
                console.log('Hello ' + name);
            }
        })();

        // 1、只能修改 setTimeout 到 Math.floor(Math.random() * 1000 的代码
        // 2、不能修改 Math.floor(Math.random() * 1000
        // 3、不能使用全局变量

        function print(n) {
            setTimeout(() => {
                console.log(n);
            }, Math.floor(Math.random() * 1000));
        }
        for (var i = 0; i < 100; i++) {
            print(i);
        }

        function changeObjProperty(o) {
            o.siteUrl = "http://www.baidu.com"
            o = new Object()
            o.siteUrl = "http://www.google.com"
        }
        let webSite = new Object();
        changeObjProperty(webSite);
        console.log(webSite.siteUrl);


        Function.prototype.a = 1;
        Object.prototype.a = 2;
        function fn() { }
        let obj = new fn();
        console.log(obj.a);
        console.dir(obj)


        // example 1
        var a = {}, b = '123', c = 123;
        a[b] = 'b';
        a[c] = 'c';
        console.log(a[b]);


        // example 2
        var a = {}, b = Symbol('123'), c = Symbol('123');
        a[b] = 'b';
        a[c] = 'c';
        console.log(a[b]);


        // example 3
        var a = {}, b = { key: '123' }, c = { key: '456' };
        a[b] = 'b';
        a[c] = 'c';
        console.log(a[b]);



        var a = { n: 1 };
        var b = a;
        a.x = a = { n: 2 };

        console.log(a.x)
        console.log(b.x)


        var a = 10;
        (function () {
            console.log(a)
            a = 5
            console.log(window.a)
            var a = 20;
            console.log(a)
        })()



        // var a = ?;
        // if(a == 1 && a == 2 && a == 3){
        //  	console.log(1);
        // }

        var b = 10;
        (function b() {
            b = 20;
            console.log(b);
        })();

        var b = 10;
        (function b() {
            b = 20;
            console.log(b);
        })();

        for (var i = 0; i < 10; i++) {
            setTimeout(() => {
                console.log(i);
            }, 1000)
        }

    </script>
</body>

</html>